import fly from '../request'

let host = 'https://aip.baidubce.com'

let baiduApi = (api, params) => {
	return new Promise((resolve, reject) => {
		fly
			.post(host + api, params, {
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			})
			.then(response => {
				resolve(response)
			})
			.catch(error => {
				reject(error)
			})
	})
}

let getAccessToken = params => {
	return baiduApi('/oauth/2.0/token', params)
}

let faceDetection = params => {
	return baiduApi('/rest/2.0/face/v3/detect', params)
}

export default {
	getAccessToken, // 获取百度access_token
	faceDetection //人脸识别
}
